# 导包
from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep

# 实例化浏览器
driver = webdriver.Edge()
# 网址
my_url = 'https://www.leafground.com/alert.xhtml'
# 打开网页
driver.get(my_url)
# 窗口最大化
driver.maximize_window()

# alert警告框处理
driver.find_element(By.XPATH, '//*[@id="j_idt88:j_idt91"]/span[2]').click()
alert = driver.switch_to.alert
# 增加强制等待时间2秒查看效果
sleep(2)
# 点击确定
alert.accept()

# Alert (Confirm Dialog)，有确定和取消按钮的弹框
driver.find_element(By.XPATH, '//*[@id="j_idt88:j_idt93"]/span[2]').click()
alert = driver.switch_to.alert
sleep(2)
# alert.accept()
# 点击取消
alert.dismiss()

# Sweet Alert (Simple Dialog)，是一个自定义的弹框库
driver.find_element(By.XPATH, '//*[@id="j_idt88:j_idt95"]/span[2]').click()
# 若是在内联框架里面，需要先切入内联框架
# driver.switch_to.frame(0)
driver.find_element(By.XPATH, '//*[@id="j_idt88:j_idt98"]/span[2]').click()

# Sweet Modal Dialog，是一个自定义的弹框库
driver.find_element(By.XPATH, '//*[@id="j_idt88:j_idt100"]/span[2]').click()
sleep(2)
driver.find_element(By.XPATH, '//*[@id="j_idt88:j_idt101"]/div[1]/a/span').click()

# 等待3秒
sleep(3)
# 关闭实例化浏览器
driver.quit()